﻿<script setup>
    import { ref, computed } from 'vue';

    const count = ref(2);
    /*计算属性在count的值小于等于3时，将返回count的值
    当count的值大于等于4时，将会返回满足条件的最后一个值，
    直到count的值再次小于等于3为止。
    */
   /* const alwaysSmall = computed((prevoius) => {
        if (count.value <= 3) {
            return count.value;
        }
        return prevoius;
    })*/

    const alwaysSmall = computed({
        get(prevoius) {
            if (count.value <= 3) {
                return count.value;
            }
            return prevoius;
        },
        set(newValue) {
            count.value = newValue * 2
        }
    });

    alwaysSmall.value = 0;
</script>

<template>
    <p>{{alwaysSmall}}</p>
</template>